home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / NPP.PAK / COMBOBAR.CPP next >
C/C++ Source or Header  |  1997-05-06  |  3KB  |  118 lines

  1. // combobar.cpp : implementation of the CComboToolBar and CTBComboBox class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12. //
  13.  
  14. #include "stdafx.h"
  15. #include "np.h"
  16. #include "combobar.h"
  17. #include "mainfrm.h"
  18. #include "npdoc.h"
  19. #include "npview.h"
  20. #include "finddlg.h"
  21.  
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. BEGIN_MESSAGE_MAP(CComboToolBar, CToolBar)
  28.     //{{AFX_MSG_MAP(CComboToolBar)
  29.     //}}AFX_MSG_MAP
  30.     ON_CBN_SETFOCUS(IDW_COMBO, OnSetFocus)    
  31. END_MESSAGE_MAP()
  32.  
  33.  
  34. void CComboToolBar::OnSetFocus()
  35. {
  36.     // combobox is gaining focus, highlight text in edit control
  37.     m_toolBarCombo.SetEditSel(0,-1);
  38. }
  39.  
  40. BOOL CComboToolBar::PreTranslateMessage(MSG* pMsg)
  41. {
  42.     // Note: there is only one control in the toolbar that accepts keyboard input,
  43.     // this is the combobox.
  44.     
  45.     // user hit ENTER
  46.     if (pMsg->wParam == VK_RETURN && GetKeyState(VK_RETURN) < 0)
  47.     {
  48.         // extract the text, update combobox lists, and do the search
  49.         CString s1;
  50.         m_toolBarCombo.GetWindowText(s1);
  51.  
  52.         if(s1.GetLength())
  53.         {
  54.             CNotepadView* pView = GetApplicationView();
  55.             m_toolBarCombo.SetEditSel(0, -1);
  56.             pView->m_searchHistory.AddString(s1);     // update combobox history list
  57.             pView->m_pFindDialog->m_szText = s1;                // update last string
  58.             pView->OnViewFindNext(s1);                        // find the string
  59.             return TRUE;  // key processed
  60.         }
  61.         else
  62.         {
  63.             MessageBeep(MB_ICONEXCLAMATION);
  64.             return TRUE;  // key processed
  65.         }
  66.     }
  67.  
  68.     // user hit ESC
  69.     if (pMsg->wParam == VK_ESCAPE && GetKeyState(VK_ESCAPE) < 0)
  70.     {
  71.         GetApplicationView()->SetFocus();
  72.         return TRUE; // key processed
  73.     }
  74.  
  75.     // user hit DOWN-ARROW
  76.     if (pMsg->wParam == VK_DOWN && GetKeyState(VK_DOWN) < 0 &&
  77.         m_toolBarCombo.GetDroppedState() == FALSE)
  78.     {
  79.         m_toolBarCombo.ShowDropDown();
  80.         return TRUE; // key processed
  81.     }
  82.  
  83.     return     CToolBar::PreTranslateMessage(pMsg);
  84. }
  85.  
  86. BEGIN_MESSAGE_MAP(CTBComboBox, CComboBox)
  87.     //{{AFX_MSG_MAP(CTBComboBox)
  88.     ON_WM_CREATE()
  89.     //}}AFX_MSG_MAP
  90. END_MESSAGE_MAP()
  91.  
  92. int CTBComboBox::OnCreate(LPCREATESTRUCT lpCreateStruct)
  93. {
  94.     if (CComboBox::OnCreate(lpCreateStruct) == -1)
  95.         return -1;
  96.  
  97.     LOGFONT logFont;
  98.     TEXTMETRIC tm;
  99.     CClientDC dc(this);
  100.  
  101.     dc.GetTextMetrics(&tm);
  102.     ::EnumFontFamilies(dc.m_hDC, _T("MS Sans Serif"), 
  103.                         CTBComboBox::FontEnumProc, (LPARAM)&logFont); 
  104.  
  105.     // change the weight and create the font
  106.     logFont.lfWeight = FW_BOLD;
  107.     if (m_font.CreateFontIndirect(&logFont))
  108.         SetFont(&m_font);
  109.  
  110.     return 0;
  111. }
  112.  
  113. int CALLBACK CTBComboBox::FontEnumProc(const LOGFONT *pLogFont, const TEXTMETRIC *pTextMetric, DWORD type, LPARAM pDestLogFont)
  114. {
  115.     memcpy((BYTE*)pDestLogFont, pLogFont, sizeof(LOGFONT));
  116.     return FALSE; // return the first font in the family(i.e. smallest).
  117. }
  118.